/*
 * Copyright Radosław Smogura, 2012. All rights reserved.
 *
 * The content of this file is confidential and it is intelectual property
 * of copyright owners.
 * 
 *
 * $URL: http://reprap-ide.googlecode.com/svn/trunk/RepRapIDE/RepRapProject/src/main/java/eu/softper/reprap/generator/NumericFactoryBigDecimal.java $
 * $Id: NumericFactoryBigDecimal.java 3 2012-11-19 10:58:30Z mail@smogura.eu $
 * $Revision: 3 $
 */
package eu.softper.reprap.generator;

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 *
 * @author rsmogura
 */
public class NumericFactoryBigDecimal extends NumericFactory<BigDecimal> {
    private int scale = 100;
    private RoundingMode rm = RoundingMode.FLOOR;
    private static final BigDecimal DEG_360 = BigDecimal.valueOf(360);
    
    @Override
    public BigDecimal valueOf(double val) {
        return BigDecimal.valueOf(val);
    }

    @Override
    public BigDecimal valueOf(BigDecimal val) {
        return val;
    }

    @Override
    public boolean isPositive(BigDecimal t) {
        return BigDecimal.ZERO.compareTo(t) < 0;
    }

    @Override
    public boolean isNegative(BigDecimal t) {
        return BigDecimal.ZERO.compareTo(t) > 0;
    }

    @Override
    public boolean isNotZero(BigDecimal t) {
        return BigDecimal.ZERO.compareTo(t) != 0;
    }

    @Override
    public BigDecimal negate(BigDecimal t) {
        return t.negate();
    }

    @Override
    public BigDecimal add(BigDecimal a, BigDecimal b) {
        return a.add(b);
    }

    @Override
    public BigDecimal mul(BigDecimal a, BigDecimal b) {
        return a.multiply(b);
    }

    @Override
    public BigDecimal div(BigDecimal a, BigDecimal b) {
        return a.divide(b, scale, rm);
    }

    @Override
    public BigDecimal subs(BigDecimal a, BigDecimal b) {
        return a.subtract(b);
    }

    @Override
    public BigDecimal reminder(BigDecimal a, BigDecimal b) {
        return a.remainder(b);
    }

    @Override
    public BigDecimal abs(BigDecimal t) {
        return t.abs();
    }

    @Override
    public BigDecimal degreeAsRemainder(BigDecimal degree) {
        BigDecimal rest = degree.remainder(DEG_360);
        if (isNegative(rest))
            return rest.add(DEG_360);
        else
            return rest;
    }

    @Override
    public BigDecimal min(BigDecimal a, BigDecimal b) {
        return a.min(b);
    }

    @Override
    public BigDecimal max(BigDecimal a, BigDecimal b) {
        return a.max(b);
    }

    @Override
    public BigDecimal round(BigDecimal a, BigDecimal r) {
        BigDecimal integer = a.divideToIntegralValue(r);
        return r.multiply(integer);
    }
    
}
